<template>
  <div class="customer-cooperation">
    <div class="customer-cooperation-header">
      <div class="customer-cooperation-title">合作中的客户（分析）</div>
    </div>
    <ElTabs v-model="searchType" @tab-change="onChange">
      <ElTabPane
        v-for="(item, index) in tabs"
        :key="index"
        :label="item.label"
        :name="item.value"
      ></ElTabPane>
    </ElTabs>

    <ElTable v-loading="loading" :data="list" max-height="700">
      <ElTableColumn type="index" label="#" :width="50" align="center" />
      <ElTableColumn prop="label" label="分类" />
      <ElTableColumn prop="value" label="值" />
      <ElTableColumn prop="value" label="占比">
        <template #="{ row }">
          {{ row.proportion || 0 }}%
        </template>
      </ElTableColumn>
    </ElTable>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { getStatistics2 } from '../api'

const searchType = ref(1)
const tabs = computed(() => {
  return [
    { label: '平台', value: 1 },
    { label: '店铺类别', value: 2 },
    { label: '客服类型', value: 3 },
    { label: '服务班次', value: 4 },
    { label: '营销类型', value: 5 },
    { label: '拓客渠道', value: 6 },
    { label: '客户所在地', value: 7 }
  ]
})

const loading = ref(false)
const list = ref([])

const getData = () => {
  loading.value = true
  getStatistics2({searchType: searchType.value})
    .then(res => {
      list.value = res || []
    })
    .finally(() => {
      loading.value = false
    })
}

const onChange = () => {
  getData()
}

onMounted(() => {
  getData()
})
</script>

<style scoped lang="scss">
.customer-cooperation{
  height: 816px;
  padding: 20px;
  box-sizing: border-box;
  &-title {
    font-family: PingFangSC-Medium;
    font-weight: 500;
    font-size: 16px;
    color: #333333;
    margin-bottom: 4px;
  }
  &-header {
    font-family: PingFangSC-Medium;
    font-weight: 500;
    font-size: 16px;
    color: #333333;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}
</style>
